const http = require('../../../utils/http.js');
Page({
  data: {
    currentTab: 0,
    heightVal: 500,
    up: "下拉加载更多~",
    navScrollLeft: 0,
    typelist: '',
    statusd: 1
  },
  onLoad: function (options) {
    var _this = this,
      typelist = wx.getStorageSync('orderTap')
    _this.setData({
      currentTab: options.type,
      typelist: typelist
    })
    //获取元素宽高
    wx.getSystemInfo({
      success: (res) => {
        _this.setData({
          windowWidth: res.windowWidth,
          navScrollLeft: (options.type - 1) * (res.windowWidth / 5)
        })
      },
    })
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2]
    let prevPage2 = pages[pages.length - 3]
    let prevPage3 = pages[pages.length - 4]
    console.log(prevPage, prevPage2, prevPage3)
    _this.getOrder(options.type)
  },
  //点击切换
  clickTab: function (e) {
    var _this = this,
      currentTab = e.currentTarget.id,
      singleNavWidth = _this.data.windowWidth / 5;
    _this.setData({
      navScrollLeft: (currentTab - 1) * singleNavWidth
    })
    console.log(currentTab)
    if (_this.data.currentTab === currentTab) {
      return false;
    } else {
      _this.setData({
        currentTab: currentTab,
      })
      _this.getOrder(currentTab)
    }
  },
  onReady: function () {},
  //获取订单数据
  getOrder(e) {
    var _this = this
    http.getRequest('v1/order', {
        status: e ? e : -1
      },
      function (res) {
        console.log(res)
        _this.setData({
          info: res.data.list,
          statusd: 0
        })
      },
      function (err) {
        setTimeout(() => {
          _this.setData({
            statusd: 0
          })
        }, 1000);
      })
  },
  check(e) {
    let order_num = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/onNewPages/Logistics/logistics?id=' + order_num,
    })
  },
  toPays(e) {
    var _this = this,
      order_num = e.currentTarget.dataset.order,
      tapList = _this.data.typelist
    for (let i in tapList) {
      if (tapList[i].status == _this.data.currentTab) {
        wx.navigateTo({
          url: '/pages/onNewPages/waitPay/waitPay?id=' + order_num + '&title=' + tapList[i].apply_name,
        })
        return false
      }
    }
  },
  toPay(e) {
    wx.navigateTo({
      url: '/pages/onNewPages/selfOrderPay/selfOrderPay?order_num=' + e.currentTarget.id + '&type=' + 1,
    })
  },
  _onShowModal(e) {
    var _this = this
    wx.showModal({
      title: '温馨提示',
      content: '是否取消订单',
      success(res) {
        if (res.confirm) {
          http.getRequest('v1/invalidOrder', {
              order_num: e.currentTarget.id
            },
            function (res) {
              console.log(res)
              wx.showToast({
                title: '取消成功',
                icon: 'success'
              })
              setTimeout(() => {
                _this.getOrder(_this.data.currentTab)
              }, 1500);
            },
            function (err) {})
        }
      }
    })
  }
})